#include"../../include/object/world.hpp"
#include"../../include/camera/camera.hpp"
#include"../../include/object/cube.hpp"
#include"../../include/dot.hpp"
#include"../../include/vector4.hpp"
#include"../../include/object/round.hpp"

namespace object{

    template<typename T>
    void ColorWorld::insertColorObject(const T& colorObject){
        // 所有的颜色物体，都有顶点std::vector<Dot> vertices,彩色三角形std::vector<ColorTriangle> colorTriangles
        // 但是考虑到可能会已经有其他物体已经插入，导致colorTriangles内部的index发生变化，这里需要对三角形的索引进行重新计算
        // 首先得到当前的顶点数量
        int currentVertexCount = this->vertices.size();
        //得到当前三角形的数量
        int currentTriangleCount = this->colorTriangles.size();
        // 插入所有顶点
        this->vertices.insert(this->vertices.end(), colorObject.vertices.begin(), colorObject.vertices.end());
        // 插入所有三角形
        this->colorTriangles.insert(this->colorTriangles.end(), colorObject.colorTriangles.begin(), colorObject.colorTriangles.end());
        // 重新计算刚刚插入的所有三角形的索引
        for(int i = currentTriangleCount; i < this->colorTriangles.size(); ++i){
            this->colorTriangles[i].index1 += currentVertexCount;
            this->colorTriangles[i].index2 += currentVertexCount;
            this->colorTriangles[i].index3 += currentVertexCount;
        }
    }
    

    // 生成一个简单的直视着的一个正方体,并且是一个只有点的
    World generateWorld1(){
        World world;
        world.camera=camera::generateCamera1();
        object::Cube cube(Dot(0,0,-500),100);
        world.objects.push_back(cube);
        //object::ColorRound round(Dot(0,0,-500),100,Vector4(0,0,0),1,0,0);
        //world.objects.push_back(round);
        return world;
    }
    // 生成一个单一颜色的圆
    ColorWorld generateWorld2(){
        ColorWorld world;
        world.camera=camera::generateCamera1();
        object::ColorRound round(Dot(0,0,-500),100,Vector4(0,0,0),0,1,0);
        world.insertColorObject(round);
        return world;
    }

    ColorWorld generateWorld3(){
        ColorWorld world;
        world.camera=camera::generateCamera2();
        object::ColorCube cube(Dot(0,0,-500),100);
        world.insertColorObject(cube);
        return world;
    }
    // 生成一个什么都没有的世界
    ColorWorld generateWorld4(camera::Camera camera){
        ColorWorld world;
        world.camera=camera;
        return world;
    }

}